class History < ActiveRecord::Base
  
  belongs_to :sprint
  has_and_belongs_to_many :tags

  has_many   :task
  has_many   :test_case
  has_many   :impediment
  has_many   :note

  
  # returns the history status.
  def status
      
      task = self.task(:first, :order => "day DESK")

      if ( task.size == 0 )
        return "&nbsp;"
      end
      
      task = task.first
      
      if ( task.done == nil || task.undone == nil )
        return "?"
      end
      
      if ( task.done == task.undone )
        return "<span class='done'>done</span>"
      end

      return (task.done / task.undone).to_s + "%"

  end
  
  def last_task( day )
    
    
    task = Task.find(:first, :conditions => [
        "history_id = :id AND day < :adate",
        { :id => self.id, :adate => day }
        
      ],
        :order => "day DESC"
      )

    return task


  #Similarly, a simple hash without a statement will generate conditions based on equality with the SQL AND operator. For instance:

  #Student.find(:all, :conditions => { :first_name => "Harvey", :status => 1 })
  #Student.find(:all, :conditions => params[:student])
    
    
    
    return task
    
    
    
  end
  
  
  
end
